package com.magic.uschat.util;

import java.util.Date;

import com.magic.uschat.Config;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.provider.SyncStateContract.Constants;

public class SharedUtils {
	private static final String SP_NAME = "app.ini";
	private static final String FL_UP_TIME = "friendListUpdateTime";
	private static final String FL_SET_NOTIFYCATION = "set_notifycation";
	private static final String FL_SET_VIBRATE = "set_vibrate";
	
	
	public static void setNotifycation(Context context,boolean flag){
		Config.NOTIFYCATION = flag;
		SharedPreferences sp = context.getSharedPreferences(SP_NAME,Context.MODE_PRIVATE);
		Editor et = sp.edit();
		et.putBoolean(FL_SET_NOTIFYCATION, flag);
		et.commit();
	}
	public static boolean getNotifycation(Context context){
		SharedPreferences sp = context.getSharedPreferences(SP_NAME,Context.MODE_PRIVATE);
		return sp.getBoolean(FL_SET_NOTIFYCATION, true);
	}
	
	public static void setVibrate(Context context,boolean flag){
		Config.VIBRATE = flag;
		SharedPreferences sp = context.getSharedPreferences(SP_NAME,Context.MODE_PRIVATE);
		Editor et = sp.edit();
		et.putBoolean(FL_SET_VIBRATE, flag);
		et.commit();
	}
	public static boolean getVibrate(Context context){
		SharedPreferences sp = context.getSharedPreferences(SP_NAME,Context.MODE_PRIVATE);
		return sp.getBoolean(FL_SET_VIBRATE, true);
	}
	
	
	
	public static void setFriendListUpdateTime(Context context){
		setFriendListUpdateTime(context, new Date());
	}
	public static void setFriendListUpdateTime(Context context,Date date){
		SharedPreferences sp = context.getSharedPreferences(SP_NAME,Context.MODE_PRIVATE);
		Editor et = sp.edit();
		et.putLong(FL_UP_TIME, date.getTime());
		et.commit();
	}
	
	public static long getFriendListUpdateTime(Context context){
		SharedPreferences sp = context.getSharedPreferences(SP_NAME,Context.MODE_PRIVATE);
		return sp.getLong(FL_UP_TIME, new Date().getTime());
	}
}
